# asterisk-base.pm
# Copyright (C) 2006-2007  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

# This file is part of the CarrierClass.net project.
# For more information: http://carrierclass.net/
#
package CCNv2::Provision::Asterisk::base;
use strict;
use warnings;
use base qw(CCNCore::Provision::Base);
use CCN::Text;
use CCNCore::Scripting;

sub run()
{
    my $self = shift;
    return if $self->p->force_manager;
    
    $self->PACKAGE ('asterisk');
    $self->PACKAGE ('asterisk-sounds-extra');

    $self->CHECKFOR ('/etc/asterisk');
    $self->CHECKFOR ('/usr/lib/asterisk/modules');
    $self->CHECKFOR ('/usr/lib/asterisk/modules/res_config_mysql.so');
    $self->CHECKFOR ('/usr/lib/asterisk/modules/app_addon_sql_mysql.so');
    $self->CHECKFOR ('/var/lib/asterisk/');
    $self->CHECKFOR ('/var/spool/asterisk/voicemail'); # Not installed by the CCN CD ?
    $self->CHECKFOR ('/var/log/asterisk'); # Not installed by the CCN CD ?
    $self->CHECKFOR ('/usr/share/asterisk/sounds');

    # Should Asterisk be enabled?
    return $self->disable('asterisk') unless defined $self->p->{cp_member};

    $self->enable('asterisk');

    # Debian base
    if($self->p->{operating_system} =~ /^(debian|ccn)/ )
    {
        # YYY I disabled safe_asterisk because things were getting really messy on my lab servers. Figure out whether it's still a "safe" option or not.
        CAT '/etc/default/asterisk', <<"EOT";
RUNASTERISK=yes
RUNASTSAFE=no
# RUNASTSAFE=yes
# AST_REALTIME=yes
# PARAMS=-v
ulimit -n 65536
EOT
        CCNv2::Scripting::IF_CHANGED_restart_asterisk('/etc/default/asterisk');
    }
    # else
    # YYYPORT RedHat base
    # {   }

}
1;